package com.rickpan.dto.share;

/**
 * 分享访问响应DTO
 * 
 * @author RickPan Team
 * @since 2025-01-05
 */
public class ShareAccessResponse {

    /**
     * 是否允许访问
     */
    private Boolean allowed;

    /**
     * 访问令牌 (临时token，用于后续文件操作)
     */
    private String accessToken;

    /**
     * 文件预览URL
     */
    private String previewUrl;

    /**
     * 文件下载URL
     */
    private String downloadUrl;

    /**
     * 权限信息
     */
    private PermissionInfo permissions;

    /**
     * 文件信息
     */
    private FileInfo fileInfo;

    /**
     * 错误信息 (当allowed为false时)
     */
    private String errorMessage;

    // 构造函数
    public ShareAccessResponse() {}

    // Getter 和 Setter 方法
    public Boolean getAllowed() { return allowed; }
    public void setAllowed(Boolean allowed) { this.allowed = allowed; }

    public String getAccessToken() { return accessToken; }
    public void setAccessToken(String accessToken) { this.accessToken = accessToken; }

    public String getPreviewUrl() { return previewUrl; }
    public void setPreviewUrl(String previewUrl) { this.previewUrl = previewUrl; }

    public String getDownloadUrl() { return downloadUrl; }
    public void setDownloadUrl(String downloadUrl) { this.downloadUrl = downloadUrl; }

    public PermissionInfo getPermissions() { return permissions; }
    public void setPermissions(PermissionInfo permissions) { this.permissions = permissions; }

    public FileInfo getFileInfo() { return fileInfo; }
    public void setFileInfo(FileInfo fileInfo) { this.fileInfo = fileInfo; }

    public String getErrorMessage() { return errorMessage; }
    public void setErrorMessage(String errorMessage) { this.errorMessage = errorMessage; }

    public static class PermissionInfo {
        private Boolean allowPreview;
        private Boolean allowDownload;

        public PermissionInfo() {}

        public PermissionInfo(Boolean allowPreview, Boolean allowDownload) {
            this.allowPreview = allowPreview;
            this.allowDownload = allowDownload;
        }

        public Boolean getAllowPreview() { return allowPreview; }
        public void setAllowPreview(Boolean allowPreview) { this.allowPreview = allowPreview; }

        public Boolean getAllowDownload() { return allowDownload; }
        public void setAllowDownload(Boolean allowDownload) { this.allowDownload = allowDownload; }
    }

    public static class FileInfo {
        private Long fileId;
        private String fileName;
        private Long fileSize;
        private String mimeType;
        private String sharerName;

        public FileInfo() {}

        public FileInfo(Long fileId, String fileName, Long fileSize, String mimeType, String sharerName) {
            this.fileId = fileId;
            this.fileName = fileName;
            this.fileSize = fileSize;
            this.mimeType = mimeType;
            this.sharerName = sharerName;
        }

        public Long getFileId() { return fileId; }
        public void setFileId(Long fileId) { this.fileId = fileId; }

        public String getFileName() { return fileName; }
        public void setFileName(String fileName) { this.fileName = fileName; }

        public Long getFileSize() { return fileSize; }
        public void setFileSize(Long fileSize) { this.fileSize = fileSize; }

        public String getMimeType() { return mimeType; }
        public void setMimeType(String mimeType) { this.mimeType = mimeType; }

        public String getSharerName() { return sharerName; }
        public void setSharerName(String sharerName) { this.sharerName = sharerName; }
    }

    /**
     * 创建成功访问响应
     */
    public static ShareAccessResponse success(String accessToken, String previewUrl, String downloadUrl,
                                            PermissionInfo permissions, FileInfo fileInfo) {
        ShareAccessResponse response = new ShareAccessResponse();
        response.setAllowed(true);
        response.setAccessToken(accessToken);
        response.setPreviewUrl(previewUrl);
        response.setDownloadUrl(downloadUrl);
        response.setPermissions(permissions);
        response.setFileInfo(fileInfo);
        return response;
    }

    /**
     * 创建失败访问响应
     */
    public static ShareAccessResponse failure(String errorMessage) {
        ShareAccessResponse response = new ShareAccessResponse();
        response.setAllowed(false);
        response.setErrorMessage(errorMessage);
        return response;
    }
}
